package com.smag.web.controller.echarts.bar;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.smag.echarts.domain.EchartsLineArea;
import com.smag.echarts.service.IEchartsLineAreaService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smag.common.annotation.Log;
import com.smag.common.core.controller.BaseController;
import com.smag.common.core.domain.AjaxResult;
import com.smag.common.enums.BusinessType;
import com.smag.common.utils.poi.ExcelUtil;
import com.smag.common.core.page.TableDataInfo;

/**
 * 农作物种植面积Controller
 * 
 * @author ruoyi
 * @date 2023-04-26
 */
@RestController("lineAreaController")
@RequestMapping("/echarts/bar/area")
public class AreaController extends BaseController
{
    @Autowired
    private IEchartsLineAreaService echartsLineAreaService;

    @RequestMapping("/firstList")
    public AjaxResult firstList() {
        return success(echartsLineAreaService.firstList());
    }

    /**
     * 查询农作物种植面积列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(EchartsLineArea echartsLineArea)
    {
        startPage();
        List<EchartsLineArea> list = echartsLineAreaService.selectEchartsLineAreaList(echartsLineArea);
        return getDataTable(list);
    }

    /**
     * 导出农作物种植面积列表
     */
    @PreAuthorize("@ss.hasPermi('system:area:export')")
    @Log(title = "农作物种植面积", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EchartsLineArea echartsLineArea)
    {
        List<EchartsLineArea> list = echartsLineAreaService.selectEchartsLineAreaList(echartsLineArea);
        ExcelUtil<EchartsLineArea> util = new ExcelUtil<EchartsLineArea>(EchartsLineArea.class);
        util.exportExcel(response, list, "农作物种植面积数据");
    }

    /**
     * 获取农作物种植面积详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(echartsLineAreaService.selectEchartsLineAreaById(id));
    }

    /**
     * 新增农作物种植面积
     */
    @PreAuthorize("@ss.hasPermi('system:area:add')")
    @Log(title = "农作物种植面积", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EchartsLineArea echartsLineArea)
    {
        return toAjax(echartsLineAreaService.insertEchartsLineArea(echartsLineArea));
    }

    /**
     * 修改农作物种植面积
     */
    @PreAuthorize("@ss.hasPermi('system:area:edit')")
    @Log(title = "农作物种植面积", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EchartsLineArea echartsLineArea)
    {
        return toAjax(echartsLineAreaService.updateEchartsLineArea(echartsLineArea));
    }

    /**
     * 删除农作物种植面积
     */
    @PreAuthorize("@ss.hasPermi('system:area:remove')")
    @Log(title = "农作物种植面积", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(echartsLineAreaService.deleteEchartsLineAreaByIds(ids));
    }
}
